<?php

// 获取发放历史记录(分页)
// GET org.volist

namespace app\api\resource\org;
use think\Db;
use think\Session;
use app\api\lib\Page;

class Volist
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = ['orgLogin'];
    // 描述
    public $_description = '获取发放历史记录(分页)';
    // 参数
    public $_param  = [
        'page'  => '请求页,默认1',
        'show'  => '请求记录数量,默认10',
        'model' => '模式,0-全部(默认) 1-未使用 2-已使用'
    ];
    // 返回
    public $_return = [
        200 => '获取成功',
    ];

    public function run(&$request)
    {
        $page  = $request->get('page/d',1);
        $show  = $request->get('show/d',10);

        $model = $request->get('model/d',0);
        $orgId = Session::get('org.id');

        $table = 'code';
        $where['org_id'] = $orgId;
        
        switch ($model) {
            case 0:
                break;
            case 1:
                $where['status'] = 0;
                break;
            case 2:
                $where['status'] = 1;
                break;
        }

        $list = Db::name($table)->where($where)->order('id desc')->page($page,$show)->select();

        $pagelist = Page::run($table,$page,$show,$where,$list);

        return [200,$pagelist];
    }
}